package logic

import (
	"context"
	"zhihu/zhihurpc/zhihurpcclient"

	"zhihu/zhihuapi/internal/svc"
	"zhihu/zhihuapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProbilenAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProbilenAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProbilenAddLogic {
	return &ProbilenAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProbilenAddLogic) ProbilenAdd(req *types.ProbilenAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.ZhiHuRpc.ProblemAdd(l.ctx, &zhihurpcclient.ProblemAddRequest{
		UserId: req.UserId,
		Title:  req.Title,
		Image:  req.Image,
		Info:   req.Info,
		Like:   req.Like,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "问题发布成功",
		Data:    add,
		Code:    200,
	}, nil
}
